
package com.gemframework.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gemframework.mapper.UsersMapper;
import com.gemframework.model.entity.po.Users;
import com.gemframework.model.entity.vo.UsersVo;
import com.gemframework.service.UsersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Title: UsersServiceImpl
 * @Date: 2021-03-10 16:25:54
 * @Version: v1.0
 * @Description: 服务实现类
 * @Author: gem
 * @Email: gemframe@163.com
 * @Copyright: Copyright (c) 2020 wanyong
 * @Company: www.gemframework.com
 */
@Slf4j
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements UsersService {

    @Resource
    private UsersMapper usersMapper;

    @Override
    public IPage<Users> selUsersPage(UsersVo usersVo) {
        Page<Users> page=new Page<>(usersVo.getPageindex(),usersVo.getSize());
        Map<String,Object>map=new HashMap<>();
        map.put("types",usersVo.getTypes());
        if(usersVo.getSex()!=null&&!"".equals(usersVo.getSex())){
            map.put("sex",usersVo.getSex());
        }
        if(usersVo.getProvince()!=null&&!"".equals(usersVo.getProvince())){
            map.put("province",usersVo.getProvince());
        }
        if(usersVo.getCity()!=null&&!"".equals(usersVo.getCity())){
            map.put("city",usersVo.getCity());
        }
        if(usersVo.getGrade()!=null&&usersVo.getGradeId()!=null){
            map.put("gradeId",usersVo.getGradeId());
        }
        if(usersVo.getSubject()!=null&&usersVo.getSubject()!=null){
            map.put("subjectId",usersVo.getSubject());
        }
        if(usersVo.getSchool()!=null&&!"".equals(usersVo.getSchool())){
            map.put("school",usersVo.getSchool());
        }
        map.put("index",(usersVo.getPageindex()-1)*usersVo.getSize());
        map.put("size",usersVo.getSize());
        List<Users> list=usersMapper.selUsersPage(map);
        Integer integer = usersMapper.selUsersPageCount(map);
        page.setRecords(list);
        page.setTotal(integer);
        return page;
    }

    @Override
    public UsersVo selUsers(Integer id) {
        return usersMapper.selUsers(id);
    }

    @Override
    public int delete(Integer id) {
        return usersMapper.delete(id);
    }

    @Override
    public int updateId(Integer id) {
        return usersMapper.updateId(id);
    }

    @Override
    public List<UsersVo> listByLoginId(Integer id) {
        return usersMapper.listByLoginId(id);
    }

    @Override
    public int select(Integer id, Integer status, String creDate) {
        return usersMapper.select(id,status,creDate);
    }


}